#define _CRT_SECURE_NO_WARNINGS 1
#include"game.h"

void InitBoard(char board[ROWS][COLS],int rows,int cols,char ret)
{
	for (int i = 0; i < rows; i++)
	{
		for (int j = 0; j < cols; j++)
		{
			board[i][j] = ret;
		}
	}
}

void PrintBoard(char board[ROWS][COLS])
{
	int i = 0;
	int j = 0;
	printf("--------扫雷--------\n");
	for (int n = 0; n <= COL; n++)
	{
		printf("%d ", n);
	}
	printf("\n");
	for (i = 1; i <= ROW; i++)
	{
		printf("%d ", i);
			for (j = 1; j <= COL; j++)
			{
				printf("%c ", board[i][j]);
			}
			printf("\n");
	}
}

void SetMine(char board[ROWS][COLS])
{
	int count = 0;
	while (count != 10)
	{
		int x = rand() % ROW + 1;
		int y = rand() % COL + 1;
	
		if (board[x][y] != '1')
		{
			board[x][y] = '1';
			count++;
		}
	}

}

void Print(char Show[ROWS][COLS], char Mine[ROWS][COLS],int x,int y)
{
	//周围雷的个数 整型整数-'0'变为字符型  字符型+'0'变为整型
	int MineCount = Mine[x-1][y-1]
		+ Mine[x-1][y]
		+ Mine[x-1][y+1]
		+ Mine[x][y-1]
		+ Mine[x][y]
		+ Mine[x][y+1]
		+ Mine[x+1][y-1]
		+ Mine[x+1][y]
		+ Mine[x+1][y+1]-9*'0';
	Show[x][y] = MineCount + '0';
	PrintBoard(Show);
}


void SweepMine(char Mine[ROWS][COLS], char Show[ROWS][COLS])
{
	int x = 0;
	int y = 0;
	int k = 0;
	int count = ROW*COL-10;
	while (k<count)
	{
		scanf("%d %d", &x, &y);
		if (x >= 1 && x <= ROW && y >= 1 && y<= COL)
		{
			if (Mine[x][y] == '1')
			{
				printf("很遗憾，你踩雷了\ngame over\n");
				printf("下方为 雷 的位置图\n");
				PrintBoard(Mine);
				break;
			}
			else
			{
				k++;
				Print(Show,Mine,x,y);
			}
		}
		else
		{
			printf("输入错误，请重新输入x（1~9),y（1~9)\n");
		}

	}
	if(k==count)
	printf("恭喜你，排查出所有雷\n");

	
}

